<?php

if( !$argv ) {
	$argv = array();
}

//ini_set( "display_errors", array_search( "--display-errors", $argv ) !== false ? "On" : "Off" );
 
 
ini_set( "display_errors", "On" );
 
 
define( "XDEBUG_LOADED", extension_loaded("xdebug") ? true : false );
define( "ENABLE_COVERAGE_REPORT", XDEBUG_LOADED && array_search( "--skip-coverage", $argv )!==false);




define( "PhpFaces_TestDir", dirname( __FILE__ )."/" );

//if( array_search( "--devel", $argv ) !== false ) {
//	set_include_path( "$facesPath:".get_include_path() );
//}

require_once("PhpFaces.php");
require_once("PHPUnit2/Framework/TestCase.php");

/**
 * The base of all PhpFaces test cases. 
 */
abstract class PhpFaces_Test_AbstractPhpFacesTestCase extends PhpUnit2_Framework_TestCase {
	protected $facesContext;
	protected $lifecycle;
	
	/**
	 * A function which returns the config path to use. This can be any value that is
	 * passed into PhpFaces::SetupEnvironment. It is meant to be overridable by other
	 * tests so that they don't have to re-implement the entire setUp function.
	 */
	public function getConfigPath() {
		return null;
	}
	
	public function getViewId() {
		return "views/hardcoew/01.php";
	}
	
	/**
	 * Setup the test case with an instance of facesContext and lifecycle, as well
	 * as make that instance the current instance.
	 * @see PhpFaces_Context_FacesContext::setCurrentInstance
	 * @see PhpFaces_Context_FacesContext::setCurrentInstance
	 */
	public function setUp() {
		$_REQUEST["page"] = $this->getViewId();
		
		$this->facesContext = new PhpFaces_Context_FacesContext();
		PhpFaces_Context_FacesContext::setCurrentInstance( $this->facesContext );

		PhpFaces::SetupEnvironment( $this->getConfigPath() );

		$lifecycleFactory = PhpFaces_LifecycleFactory::GetInstance();
		$this->lifecycle =  $lifecycleFactory->getLifecycle( "default" );
	}
	
	/**
	 * Set our instance of facesContext null. Does not clean up FacesContext::currentInstance.
	 */
	public function tearDown() {
		$this->lifecycle = null;
		$this->facesContext = null;
	}
}


class TestBean {
	private $accessorProperty;
	public $fieldProperty;
	public $nestedClassProperty;
	
	public function __construct() {
		$this->fieldProperty = "field property";
		$this->accessorProperty = "accessor property";
		$this->nestedClassProperty = new StdClass();
		$this->nestedClassProperty->fieldProperty = "nested field";
	}
	
	public function getAccessorProperty() {
		return $this->accessorProperty;
	}
	
	public function setAccessorProperty( $newValue ) {
		$this->accessorProperty = $newValue;
	}
	
	public function doSomeAction() {
		return "success";
	}
	
	public $listData = 
		array(
			array( "id" => "1", "prop1" => "one1", "prop2" => "two1" ),
			array( "id" => "2", "prop1" => "one2", "prop2" => "two2" ),
			array( "id" => "3", "prop1" => "one3", "prop2" => "two3" )
		);

};
?>